/*
 * @Description: 表格列配置
 * @Author: HuiSir<https://gitee.com/huisir001>
 * @Date: 2021-11-05 11:41:30
 * @LastEditTime: 2025-08-16 00:40:58
 */
import { h } from "vue";
import { defineTableCols } from "@/components/TablePage/predefined";
import FyIcon from "@/ui/fy/Icon/index.vue";
import { PermTypeOpt, MenuTypeOpt } from "@/helpers/selection";

export default defineTableCols(() => [
  {
    label: "权限名称",
    minWidth: 140,
    prop: "title",
    fixed: "left",
    showOverflowTooltip: true,
  },
  {
    label: "权限编码",
    helpTip: "权限唯一标识",
    minWidth: 100,
    prop: "code",
    fixed: "left",
    showOverflowTooltip: true,
  },
  {
    label: "排序",
    width: 50,
    prop: "orderRank",
  },
  {
    label: "图标",
    minWidth: 50,
    prop: "icon",
    formatter: (_row, _column, cellValue: string) => {
      return cellValue
        ? h(FyIcon, { name: cellValue, size: "14", height: 16 })
        : "";
    },
  },
  {
    label: "权限类型",
    prop: "type",
    minWidth: 70,
    formatter: (_row, _column, cellValue: PermissionType) => {
      return PermTypeOpt.getLabel(cellValue);
    },
  },
  {
    label: "菜单类型",
    prop: "menuType",
    minWidth: 70,
    formatter: (_row, _column, cellValue: MenuType) => {
      return MenuTypeOpt.getLabel(cellValue);
    },
  },
  {
    label: "路径",
    prop: "path",
    formatter: (_row, _column, cellValue: string) => {
      return cellValue || "-";
    },
    width: 140,
    showOverflowTooltip: true,
  },
  {
    label: "登录权限",
    prop: "internal",
    helpTip: "是否需要登录才能访问",
    minWidth: 90,
    formatter: (_row, _column, cellValue: boolean) => {
      return cellValue ? "需要" : "不需要";
    },
  },
  {
    label: "路由组件",
    helpTip: "菜单类型为路由时可配置Vue文件路径",
    minWidth: 170,
    prop: "viewPath",
    formatter: (_row, _column, cellValue: string) => {
      return cellValue || "-";
    },
    width: 140,
    showOverflowTooltip: true,
  },
  {
    label: "缓存",
    helpTip: "路由是否缓存，缓存时切换已有路由不刷新",
    width: 60,
    prop: "keepAlive",
    formatter: (row, _column, cellValue: boolean) => {
      if (
        (row.type === PermTypeOpt.menu && row.menuType === MenuTypeOpt.route) ||
        row.type === PermTypeOpt.page
      ) {
        return cellValue ? "缓存" : "不缓存";
      } else {
        return "-";
      }
    },
  },
  {
    label: "打开方式",
    prop: "blank",
    helpTip: "路由或链接是否在浏览器新标签打开",
    minWidth: 95,
    formatter: (row, _column, cellValue: boolean) => {
      if (
        (row.type === PermTypeOpt.menu &&
          (row.menuType === MenuTypeOpt.route ||
            row.menuType === MenuTypeOpt.link)) ||
        row.type === PermTypeOpt.page
      ) {
        return cellValue ? "浏览器新标签" : "框架内";
      } else {
        return "-";
      }
    },
  },
  {
    label: "按钮事件",
    helpTip: "菜单类型为按钮时执行的方法名",
    minWidth: 140,
    prop: "triggerMethod",
    showOverflowTooltip: true,
    formatter: (_row, _column, cellValue: string) => {
      return cellValue || "-";
    },
  },
  {
    fixed: "right",
    width: 200,
    // scope.row.treeLevel === 2 ? ['edit', 'del'] : ['edit', 'add', 'del']
    useRowBtns: ["edit", "add", "del"],
    useFuzzySearch: true,
  },
]);
